<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/public.css">
</head>

<body>
    <!-- globalCompositeOperation  设置或返回如何将一个源（新的）图像绘制到目标（已有）的图像上 -->

    <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"></canvas>

    <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");

        ctx.fillStyle = "red";
        ctx.fillRect(20, 20, 75, 50);
        ctx.globalCompositeOperation = "source-over";
        ctx.fillStyle = "blue";
        ctx.fillRect(50, 50, 75, 50);

        ctx.fillStyle = "red";
        ctx.fillRect(150, 20, 75, 50);
        ctx.globalCompositeOperation = "destination-over";
        ctx.fillStyle = "blue";
        ctx.fillRect(180, 50, 75, 50);
    </script>
</body>

</html>